package com.example.xungeng2.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.xungeng2.pojo.Work;
import com.example.xungeng2.service.WorkService;
import com.example.xungeng2.service.WorkerService;
import com.example.xungeng2.unknow.TableMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/worker")
public class WorkController {

    @Autowired
    private WorkerService workerService;

    @Autowired
    private WorkService workService;

    @Cacheable(value = "workPage",key = "'workpage'")
    @GetMapping("/selectPage")
    public TableMap selectPage(long page, long limit) {
        Page<Work> workPage = workService.selectPage(page, limit);
        TableMap tableMap = new TableMap();
        tableMap.setData(workPage.getRecords());
        tableMap.setCount(workPage.getTotal());
        return tableMap;
    }

    @PostMapping("/selectPage")
    public TableMap selectPage2(long page, long limit) {
        Page<Work> workPage = workService.selectPage(page, limit);
        TableMap tableMap = new TableMap();
        tableMap.setData(workPage.getRecords());
        tableMap.setCount(workPage.getTotal());
        return tableMap;
    }
}